﻿/*1942 game clone
 * Authors:
 * Abdollah Tabareh
 * Bharat Bhushan Konka
 * Martin Svensson 
 * Richard Zianne
 * Tigran Harutyunyan
 * 
 * 2010
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;


namespace Game1942
{
    class StartScene : Scene
    {        
        private int _selectedItem = 0;
        private SpriteBatch spriteBatch;
        Texture2D _sprites;
        private KeyboardState _oldKeyState= new KeyboardState(Keys.Enter);
       
        private TimeSpan _elapsedTime = TimeSpan.MaxValue;

       


        


        public StartScene(Game game, Texture2D sp): base(game)
        {

            spriteBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            _sprites = sp;

           
            
        }
        protected override void LoadContent()
        {
           

        }
        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(_sprites, new Rectangle(0, 0, 800, 600), new Rectangle(943, 707, 80,60), Color.Wheat);            
            spriteBatch.Draw(_sprites, new Vector2(261,50),new Rectangle(102, 576, 278, 141), Color.White);
            spriteBatch.Draw(_sprites, new Vector2(290, 300), new Rectangle(580, 389, 95, 14), Color.White);
            spriteBatch.Draw(_sprites, new Vector2(290, 330), new Rectangle(580, 443, 95, 14), Color.White);
            spriteBatch.Draw(_sprites, new Vector2(290, 360), new Rectangle(580, 461, 95, 14), Color.White);
            spriteBatch.Draw(_sprites, new Vector2(261, 300 + _selectedItem * 30), new Rectangle(569, 390, 7, 12), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }

        public override void Update(GameTime gameTime)
        {

            //if (_elapsedTime.CompareTo(TimeSpan.FromSeconds(1)) < 1)
            //{
            //    _elapsedTime += gameTime.ElapsedGameTime;
            //    return;
            //}
            //_elapsedTime = TimeSpan.Zero;

            
           
            KeyboardState keyboardState = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.Up) && !_oldKeyState.IsKeyDown(Keys.Up))
            {
                _selectedItem -= 1;
                if(_selectedItem < 0)
                {
                    _selectedItem = 2;
                }
            }
            else if (keyboardState.IsKeyDown(Keys.Down) && !_oldKeyState.IsKeyDown(Keys.Down))
            {     
                _selectedItem += 1;
                if(_selectedItem > 2)
                {
                    _selectedItem = 0;
                }
            }
            else if (keyboardState.IsKeyDown(Keys.Enter) && !_oldKeyState.IsKeyDown(Keys.Enter))
            {
                if (_selectedItem == 0)
                {
                    ((Game1)Game).SetCurrentScene(0);
                }
                if (_selectedItem == 1)
                {
                    ((Game1)Game).SetCurrentScene(GameScenes.ScoreScene);
                }
                if (_selectedItem == 2)
                {
                    System.Environment.Exit(0);
                }
            }
            _oldKeyState = keyboardState;
            base.Update(gameTime);
        }
            
    }
}
